package org.harlov.testsys.views.add_forms;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

import org.harlov.testsys.db.users;
import org.harlov.testsys.views.admin_form;
import org.harlov.testsys.views.gui_factory;

public class add_stud_form extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private gui_factory gFactory;
	private JFrame mFrame;
	private admin_form own ;
	
	public add_stud_form (admin_form owner) {
		super("HTest|Добавление нового пользователя в базу");
		gFactory = new gui_factory(this);
		
		own = owner;
		mFrame = this;
		
		this.setPreferredSize(new Dimension(320,180));
		this.setSize(320,180);
		this.getContentPane().setLayout(null);
		this.setResizable(false);
		gui_factory.setCenterPosition(this);
		this.setVisible(true);
		
		
		gFactory.newLabel("ФИО", "l_fio", 10, 10, 50, 20);
		gFactory.newLabel("Логин", "l_login", 10, 30, 50, 20);
		gFactory.newLabel("Пароль", "l_pass", 10, 50, 80, 20);
		
		
		gFactory.newText("t_fio", 100,10, 200,20);
		gFactory.newText("t_login", 100,30, 200,20);
		gFactory.newText("t_pass", 100,50, 200,20);
		
		
		gFactory.newButton("Добавить", "b_ok", 10, 100,150,40,new add_ok());
		gFactory.newButton("Отмена", "b_cancel", 160, 100,150,40, new b_cancel());
		gFactory.newComboBox("combo_sel_type",users.getTypes(), 100,80);
		
		
	}
	
	class add_ok implements ActionListener  {
	@Override
	public void actionPerformed(ActionEvent arg0) {
		users.addUser(gFactory.getTextFrom("t_login"),gFactory.getTextFrom("t_pass"),gFactory.getTextFrom("t_fio"),gFactory.getSelCombo("combo_sel_type"));
		own.gFactory.getObject("tbl_studs").repaint();
		mFrame.setVisible(false);
		
	}
	
	}
	
	class b_cancel implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			mFrame.dispose();
		}
		
	}
	
	
}
